<?php
class LeagueController extends AdminBaseController {
	public function _initialize() {
		parent::_initialize();
		$this->db = model('League');
	}
/**
 *	  加盟申请列表
 *	  [Jsen.net] (C)2013-2099 Jason Group Science and technology co., LTD.
 *	  This is NOT a freeware, use is subject to license terms
 *
 *	  http://www.jsen.net
 *	  tel:400-681-9511
 */
	public function index(){
		if(IS_POST){
			$sqlmap = array();
			$order = array();
			//排序
			$_order=isset($_POST['order']) ? ($_POST['order']) : NULL;
			$_sort=isset($_POST['sort']) ? ($_POST['sort']) : NULL;
			if($_order && $_sort){
				$order[$_sort] = $_order;
			}else{
				$order['id'] = 'desc';
			}
			$pagenum=isset($_POST['page']) ? intval($_POST['page']) : 1;
			$rowsnum=isset($_POST['rows']) && (int)($_POST['rows']) != 0 ? intval($_POST['rows']) : PAGE_SIZE;
			$data['total'] = $this->db->where($sqlmap)->count();	//计算总数 
			$field = "a.*,b.area_name as prov_name,c.area_name as city_name,d.area_name as dist_name,f.type_name as hangye";
			$join = " LEFT JOIN `__REGION__` as b ON a.province=b.area_id";
			$join.= " LEFT JOIN `__REGION__` as c ON a.city=c.area_id";
			$join.= " LEFT JOIN `__REGION__` as d ON a.city=d.area_id";	
			$join.= " LEFT JOIN `__UNION_TYPE__` as f ON a.fenlei=f.id";	
			$data['rows'] = $this->db->alias('a')->field($field)->join($join)->where($sqlmap)->limit(($pagenum-1)*$rowsnum.','.$rowsnum)->order($order)->select();
			foreach ($data['rows'] as $key => $value) {
				$data['rows'][$key]['address'] = $value["prov_name"].$value["city_name"].$value["dist_name"].$value["address"];
			}
			if (!$data['rows']) $data['rows']=array();
			echo json_encode($data);
		}else{
			include $this->admin_tpl('league_index');
		}
			
	}
	
	/**
	 * 状态修改
	 * @author nbnat.com
	 */
	public function changeStatus($method=null){
		if ( empty($_GET['id']) ) {
		  showmessage('请选择要操作的数据!');
		} 
		$id=$_GET['id'];
		$method = $_GET['method'];
		$db=model('League');
		switch ( strtolower($method) ){
			case '1':
				$data['status']=0;
				$db->where('id='.$id)->save($data);
			  showmessage('成功处理',null,1);
				break;
			case '0':
				$data['status']=1;
				$db->where('id='.$id)->save($data);
			  showmessage('成功处理',null,1);
				break;
			default:
			  showmessage($method.'参数非法');
		}
	}
	
}	
